package br.com.locanet.session.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import br.com.locanet.bean.impl.CarroLocacao;
import br.com.locanet.bean.impl.CopiaFilme;
import br.com.locanet.service.impl.CopiaFilmeService;

public class LocaNetSessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent se) {
		
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		System.out.println("aqui");
		CarroLocacao carrinho;
		if (se.getSession().getAttribute("carrinho")!=null){
			 carrinho = (CarroLocacao) se.getSession().getAttribute("carrinho");
			 for (CopiaFilme copia : carrinho){
				copia.setStatus(1);
				try {
					getCopiaFilmeService().update(copia);
				} catch (Exception e) {
					e.printStackTrace();
				}
			 }
		}
	}
	
	private CopiaFilmeService getCopiaFilmeService(){
		return new CopiaFilmeService();
	}
}
